//
//  TMWebViewController.swift
//  TimMusic
//
//  Created by nkl on 2024/10/15.
//

import Foundation
import WebKit

class TMWebViewController: BasicBGViewController {
    lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "ic_back"), for: .normal)
        btn.addTarget(self, action: #selector(dimissCurrentVc), for: .touchUpInside)
        return btn
    }()

    lazy var webView: WKWebView = {
        let web = WKWebView()
        return web
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func loadData(url:URL){
        let req : URLRequest = .init(url: url)
        webView.load(req)
    }

    override func addChildren() {
        super.addChildren()
        view.addSubview(backButton)
        view.addSubview(webView)
        TMTabbarViewController.rootTabbar?.hideSelectedBar()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        TMTabbarViewController.rootTabbar?.showSelectedBar()
    }

    override func makeConstraints() {
        super.makeConstraints()

        backButton.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.width.height.equalTo(24)
            make.leading.equalToSuperview().offset(16)
        }

        webView.snp.makeConstraints { make in
            make.top.equalTo(backButton.snp.bottom)
            make.leading.trailing.equalToSuperview()
            make.bottom.equalToSuperview()
        }
    }

    @objc func dimissCurrentVc() {
        navigationController?.popViewController(animated: true)
    }
}
